package JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBC_Util {

public static Connection getConnection() throws SQLException,ClassNotFoundException{
		
		Class.forName("com.mysql.jdbc.Driver");
		String url = "jdbc:mysql://localhost:3306/tank_war";
		String username = "root";
		String password = "root";
		Connection conn = DriverManager.getConnection(url,username,password);
		return conn;	
	}
	

	public static void release(Statement stmt,Connection conn) throws SQLException{
		if(stmt != null){
			stmt.close();
			stmt = null;
		}
		if(conn != null){
			conn.close();
			conn = null;
		}
	}


	public static void release(ResultSet rs,Statement stmt,Connection conn) throws SQLException{
		if(rs != null){
			rs.close();
			rs = null;
		}if(stmt != null){
			stmt.close();
			stmt = null;
		}
		if(conn != null){
			conn.close();
			conn = null;
		}
	}


	public static void release(PreparedStatement prestmt,Connection conn) throws SQLException{
		if(prestmt != null){
			prestmt.close();
			prestmt = null;
		}
		if(conn != null){
			conn.close();
			conn = null;
		}
	}


	public static void release(ResultSet rs,Statement stmt,Connection conn,PreparedStatement prestmt ) throws SQLException{
		if(rs != null){
			rs.close();
			rs = null;
		}if(stmt != null){
			stmt.close();
			stmt = null;
		}
		if(conn != null){
			conn.close();
			conn = null;
		}
		if(prestmt != null){
			prestmt.close();
			prestmt = null;
		}
	}

}
